package com.zcxk.config;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class Environment implements Serializable {

    /**
     * 是 string
     * 平台 iOS /Android
     */
    private String platform;
    /**
     * 平台版本 安卓7.1 ios12
     */
    private String platformVersion;
    /**
     * 手机型号 p20
     */
    private String platformModel;
    /**
     * 手机品牌 华为
     */
    private String platformBrand;
    /**
     * 应用包名 com.ky
     */
    private String bundle;
    /**
     * 客户端版本号 1.01
     */
    private String clientVersion;
    /**
     * 设备的唯一标识
     */
    private String deviceId;
    /**
     * 网络类型: WIFI/4G/3G
     */
    private String networkType;

    private String ip;
    /**
     * 投放渠道--这个用户从哪一个渠道来
     */
    private String utmSource;
    /**
     * 语言版本
     */
    private String lan;
    private String token;
    /**
     * imei
     */
    private String imei;
    /**
     * 国家
     */
    private String country;
    /**
     * 运营商 例:中国移动
     */
    private String carrier;
    /**
     * 用户时区
     */
    private String timeZone;
    /**
     * 来源于 token 因此需要先解析token
     */
    private Long uid;
    private String oaid;
    /**
     * 客户端自定义Agent
     */
    private String agent;
    /**
     * 客户端原生Agent
     */
    private String nativeAgent;
    private String appName;
    /**
     * 广告SDK版本号-快音自研广告SDK版本号
     */
    private String advSdkVersion;
    /**
     * 省份
     */
    private String province;
    /**
     * 城市
     */
    private String city;

    public String getPlatform() {
        return platform;
    }

    public void setPlatform(String platform) {
        this.platform = platform;
    }

    public String getPlatformVersion() {
        return platformVersion;
    }

    public void setPlatformVersion(String platformVersion) {
        this.platformVersion = platformVersion;
    }

    public String getPlatformModel() {
        return platformModel;
    }

    public void setPlatformModel(String platformModel) {
        this.platformModel = platformModel;
    }

    public String getPlatformBrand() {
        return platformBrand;
    }

    public void setPlatformBrand(String platformBrand) {
        this.platformBrand = platformBrand;
    }

    public String getClientVersion() {
        return clientVersion;
    }

    public void setClientVersion(String clientVersion) {
        this.clientVersion = clientVersion;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getNetworkType() {
        return networkType;
    }

    public void setNetworkType(String networkType) {
        this.networkType = networkType;
    }

    @JSONField(serialize = false)
    public boolean isAndroid() {
        return "a".equalsIgnoreCase(platform) || "android".equalsIgnoreCase(platform);
    }

    @JSONField(serialize = false)
    public boolean isIphone() {
        return "i".equalsIgnoreCase(platform) || "ios".equalsIgnoreCase(platform);
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getLan() {
        return lan;
    }

    public void setLan(String lan) {
        this.lan = lan;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getBundle() {
        return bundle;
    }

    public void setBundle(String bundle) {
        this.bundle = bundle;
    }

    public String getUtmSource() {
        return utmSource;
    }

    public void setUtmSource(String utmSource) {
        this.utmSource = utmSource;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCarrier() {
        return carrier;
    }

    public void setCarrier(String carrier) {
        this.carrier = carrier;
    }

    public String getTimeZone() {
        return timeZone;
    }

    public void setTimeZone(String timeZone) {
        this.timeZone = timeZone;
    }

    public String getImei() {
        return imei;
    }

    public void setImei(String imei) {
        this.imei = imei;
    }

    public Long getUid() {
        return uid;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }

    public String getOaid() {
        return oaid;
    }

    public void setOaid(String oaid) {
        this.oaid = oaid;
    }

    public String getAgent() {
        return agent;
    }

    public void setAgent(String agent) {
        this.agent = agent;
    }

    public String getNativeAgent() {
        return nativeAgent;
    }

    public void setNativeAgent(String nativeAgent) {
        this.nativeAgent = nativeAgent;
    }

    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

    public String getAdvSdkVersion() {
        return advSdkVersion;
    }

    public void setAdvSdkVersion(String advSdkVersion) {
        this.advSdkVersion = advSdkVersion;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    public Map<String, String> toHeader() {
        Map<String, String> header = new HashMap<>();
        header.put("platform", StrUtil.blankToDefault(getPlatform(), ""));
        header.put("platform-v", StrUtil.blankToDefault(getPlatformVersion(), ""));
        header.put("platform-model", StrUtil.blankToDefault(getPlatformModel(), ""));
        header.put("platform-brand", StrUtil.blankToDefault(getPlatformBrand(), ""));
        header.put("client-v", StrUtil.blankToDefault(getClientVersion(), ""));
        header.put("device-id", StrUtil.blankToDefault(getDeviceId(), ""));
        header.put("network-type", StrUtil.blankToDefault(getNetworkType(), ""));
        header.put("Java-Proxy-Client-IP", StrUtil.blankToDefault(getIp(), ""));
        header.put("lang", StrUtil.blankToDefault(getLan(), ""));
        header.put("imei", StrUtil.blankToDefault(getImei(), ""));
        header.put("bundle", StrUtil.blankToDefault(getBundle(), ""));
        header.put("country", StrUtil.blankToDefault(getCountry(), ""));
        header.put("utm-source", StrUtil.blankToDefault(getUtmSource(), ""));
        header.put("timeZone", StrUtil.blankToDefault(getTimeZone(), ""));
        header.put("oaid", StrUtil.blankToDefault(getOaid(), ""));
        header.put("User-Agent", StrUtil.blankToDefault(getAgent(), ""));
        header.put("app_name", StrUtil.blankToDefault(getAppName(), ""));
        header.put("adv-sdk-version", StrUtil.blankToDefault(getAdvSdkVersion(), ""));
        return header;
    }
}
